import 'package:flutter/material.dart';
import 'package:flutter_study/utils/toast.dart';
import 'package:simple_permissions/simple_permissions.dart';

class PermisionPage extends StatefulWidget {
  final String title;

  PermisionPage({Key key, this.title}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return PermisionPageState();
  }
}

class PermisionPageState extends State<PermisionPage> {
  String _platformVersion = 'Unknown';

  @override
  Widget build(BuildContext context) {
    // TODO: implement build

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: RaisedButton(
          onPressed: () {
            _reqPermision();
          },
          child: Text('权限请求'),
        ),
      ),
    );
  }

  void _reqPermision() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await SimplePermissions.platformVersion;
    } catch (e) {
      platformVersion = 'Failed to get platform version.';
    }

    //获取android版本
    print('===>' + platformVersion);
    PermissionStatus res = await SimplePermissions.requestPermission(Permission.WriteExternalStorage);
    Toast.toast(context, '${res}');

  }
//
//enum PermissionStatus {
//  /// Permission to access the requested feature is denied by the user.
//  denied,
//
//  /// Permissions to access the feature is granted by the user but the feature is disabled.
//  disabled,
//
//  /// Permission to access the requested feature is granted by the user.
//  granted,
//
//  /// The user granted restricted access to the requested feature (only on iOS).
//  restricted,
//
//  /// Permission is in an unknown state
//  unknown
//}
//enum PermissionGroup {
//  /// The unknown permission only used for return type, never requested
//  unknown,
//
//  /// Android: Calendar
//  /// iOS: Calendar (Events)
//  calendar,
//
//  /// Android: Camera
//  /// iOS: Photos (Camera Roll and Camera)
//  camera,
//
//  /// Android: Contacts
//  /// iOS: AddressBook
//  contacts,
//
//  /// Android: Fine and Coarse Location
//  /// iOS: CoreLocation (Always and WhenInUse)
//  location,
//
//  /// Android: Microphone
//  /// iOS: Microphone
//  microphone,
//
//  /// Android: Phone
//  /// iOS: Nothing
//  phone,
//
//  /// Android: Nothing
//  /// iOS: Photos
//  photos,
//
//  /// Android: Nothing
//  /// iOS: Reminders
//  reminders,
//
//  /// Android: Body Sensors
//  /// iOS: CoreMotion
//  sensors,
//
//  /// Android: Sms
//  /// iOS: Nothing
//  sms,
//
//  /// Android: External Storage
//  /// iOS: Nothing
//  storage,
//
//  /// Android: Microphone
//  /// iOS: Speech
//  speech,
//
//  /// Android: Fine and Coarse Location
//  /// iOS: CoreLocation - Always
//  locationAlways,
//
//  /// Android: Fine and Coarse Location
//  /// iOS: CoreLocation - WhenInUse
//  locationWhenInUse,
//
//  /// Android: None
//  /// iOS: MPMediaLibrary
//  mediaLibrary
//}
}